package com.osgix.common.utils;

import javax.servlet.http.HttpServletRequest;

import org.extremecomponents.table.context.HttpServletRequestContext;
import org.extremecomponents.table.limit.Limit;
import org.extremecomponents.table.limit.TableLimit;
import org.extremecomponents.table.limit.TableLimitFactory;

public class ExtremeTablePage
{

    public ExtremeTablePage()
    {
    }

    public static Limit getLimit(HttpServletRequest request, int defautPageSize)
    {
        return getLimit(request, 2147483647, defautPageSize, null);
    }

    public static Limit getLimit(HttpServletRequest request, int totalRows, int defautPageSize)
    {
        return getLimit(request, totalRows, defautPageSize, null);
    }

    public static Limit getLimit(HttpServletRequest request, int totalRows, int defautPageSize, String tableId)
    {
        org.extremecomponents.table.context.Context context = new HttpServletRequestContext(request);
        org.extremecomponents.table.limit.LimitFactory limitFactory = null;
        if(tableId == null)
            limitFactory = new TableLimitFactory(context);
        else
            limitFactory = new TableLimitFactory(context, tableId);
        TableLimit limit = new TableLimit(limitFactory);
        limit.setRowAttributes(totalRows, defautPageSize);
        return limit;
    }
}